<!DOCTYPE html>
<html xmlns:scrollbar="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>释放积分上限设置</title>
    <meta name="keywords" content="释放积分上限设置"/>
    <link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css"/>
</head>

<style>
    .layui-input-inline {
        margin-top: 10px;
    }

    .int {
        min-width: 50px;
    }

    .list_top_item {
        padding-top: 20px;
        flex: 1;
    }

    .mall_box_item {
        display: flex;
    }

    .list_top {
        display: flex;
        width: 150px;
        margin-top: 10px;
        padding-left: 30px;
    }

    .productIntegralRuleUpate {
        padding-top: 60px;
        margin-left: 200px;
        display: flex;
    }

    .layui-input-block{
        width: 190px;
        height: 20px;
    }
</style>

<body>
<!--弹出层一级开始-->
<div class="layui-tab">
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            <table id="plan" lay-filter="plan-filter"></table>
        </div>
    </div>
</div>
<!--弹出层一级结束-->


<!--弹出层二级开始-->
<div id="motaikuang" class="layui-row" style="display: none;" scrollbar="false">
    <div class="mall_box_item">
        <div class="list_top">
            <div class=" list_top_item">个人每日获得积分最小倍数:</div>
            <input size="5" style="width:80px;font-style: italic;"
                   id="reverse_multiple_min1" type="text"
                   lay-verify="required"
                   placeholder="个人每日获得积分最小倍数"
                   value=""/>
        </div>
        <div class="list_top">
            <div class=" list_top_item">个人每日获得积分最大倍数:</div>
            <input size="5" style="width:80px;font-style: italic;"
                   id="reverse_multiple_max1" type="text"
                   lay-verify="required"
                   placeholder="个人每日获得积分最大倍数"
                   value=""/>
        </div>
        <div class="list_top">
            <div class=" list_top_item">未完成邀请人数积分倍数:</div>
            <input size="5" style="width:80px;font-style: italic;"
                   id="reverse_multiple_count_min1" type="text"
                   lay-verify="required"
                   placeholder="未完成邀请人数积分倍数"
                   value=""/>
        </div>
        <div class="list_top">
            <div class=" list_top_item">已完成邀请人数积分倍数:</div>
            <input size="5" style="width:80px;font-style: italic;"
                   id="reverse_multiple_count_max1" type="text"
                   lay-verify="required"
                   placeholder="已完成邀请人数积分倍数"
                   value=""/>
        </div>
    </div>
</div>
<!--弹出层二级结束-->

<!--弹出层一级结束-->
<div id="insert_member_proportion" style="display: none" scrollbar="false">

    <div class="mall_box_item">
        <div class="list_top">
            <div class=" list_top_item">个人每日获得积分最小倍数:</div>
            <input size="5" style="width:80px;font-style: italic;"
                   id="reverse_multiple_min" type="text"
                   lay-verify="required"
                   placeholder="个人每日获得积分最小倍数"
                   value=""/>
        </div>
        <div class="list_top">
            <div class=" list_top_item">个人每日获得积分最大倍数:</div>
            <input size="5" style="width:80px;font-style: italic;"
                   id="reverse_multiple_max" type="text"
                   lay-verify="required"
                   placeholder="个人每日获得积分最大倍数"
                   value=""/>
        </div>
        <div class="list_top">
            <div class=" list_top_item">未完成邀请人数积分倍数:</div>
            <input size="5" style="width:80px;font-style: italic;"
                   id="reverse_multiple_count_min" type="text"
                   lay-verify="required"
                   placeholder="未完成邀请人数积分倍数"
                   value=""/>
        </div>
        <div class="list_top">
            <div class=" list_top_item">已完成邀请人数积分倍数:</div>
            <input size="5" style="width:80px;font-style: italic;"
                   id="reverse_multiple_count_max" type="text"
                   lay-verify="required"
                   placeholder="已完成邀请人数积分倍数"
                   value=""/>
        </div>
        <div id="verfiyProportion" class=" list_top_item"></div>
    </div>

</div>
<div id="GeneralIntegralSpeedCheck" class="layui-input-block" style="display:none">
    <div class="list_top">
        <div class=" list_top_item">个人每日获得积分最小倍数:</div>
        <input size="5" style="width:80px;font-style: italic;"
               id="reverse_multiple_min2" type="text"
               lay-verify="required"
               placeholder="个人每日获得积分最小倍数"
               value=""/>
    </div>
    <div class="list_top">
        <div class=" list_top_item">个人每日获得积分最大倍数:</div>
        <input size="5" style="width:80px;font-style: italic;"
               id="reverse_multiple_max2" type="text"
               lay-verify="required"
               placeholder="个人每日获得积分最大倍数"
               value=""/>
    </div>
    <div class="list_top">
        <div class=" list_top_item">未完成邀请人数积分倍数:</div>
        <input size="5" style="width:80px;font-style: italic;"
               id="reverse_multiple_count_min2" type="text"
               lay-verify="required"
               placeholder="未完成邀请人数积分倍数"
               value=""/>
    </div>
    <div class="list_top">
        <div class=" list_top_item">已完成邀请人数积分倍数:</div>
        <input size="5" style="width:80px;font-style: italic;"
               id="reverse_multiple_count_max2" type="text"
               lay-verify="required"
               placeholder="已完成邀请人数积分倍数"
               value=""/>
    </div>
</div>
</body>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getInsert">新增</button>
        <!--<button class="layui-btn layui-btn-sm" lay-event="getDelete">删除</button>-->
    </div>
</script>
<script type="text/html" id="barDemo">
    <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>-->
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" language="JavaScript" src="/static/layui/layui.js"></script>

<script>
    $(function () {
        layui.use('element', function () {
            var element = layui.element;
        });

        layui.use(['table','layer','laydate'], function () {
            var table = layui.table
            var layer = layui.layer //弹层
            table.render({
                elem: '#plan'
                , height: 500
                , url: '/system/activity/generalIntegral/getReverseMultipleRule' //数据接口
                , page: true //开启分页
                , cols: [[ //表头
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'id', title: 'ID', sort: true}
                    , {field: 'reverse_multiple_min', title: '签到最小随机数'}
                    , {field: 'reverse_multiple_max', title: '签到最大随机数', sort: true, totalRow: true}
                    , {field: 'reverse_multiple_count_min', title: '未完成邀请人数积分倍数', sort: true, totalRow: true}
                    , {field: 'reverse_multiple_count_max', title: '已完成邀请人数积分倍数', sort: true, totalRow: true}
                    , {field: 'status', title: '状态', sort: true, totalRow: true}
                    , {field: 'increment_multiple', title: '增长倍数', sort: true, totalRow: true}
                    , {field: 'create_time', title: '开始时间', sort: true, totalRow: true}
                    , {field: 'update_time', title: '结束时间', sort: true, totalRow: true}
                    , {fixed: 'right', width: 165, align: 'center', toolbar: '#barDemo'}

                ]]
                ,toolbar: '#toolbarDemo'
            });
            $(".layui-tab").css("margin","0");
            $(".layui-tab-content").css("padding","0");
            $(".layui-form.layui-border-box.layui-table-view").css("margin","0");
            table.on('toolbar(plan-filter)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id),
                    data = checkStatus.data; //获取选中的数据
                switch (obj.event) {
                    case "getInsert":
                        layer.open({
                            type: 1,//类型
                            id: "insertTab",
                            area: ['600px', '300px'],//定义宽和高
                            title: '增加购买获赠积分规则',//题目
                            shadeClose: false,//点击遮罩层关闭
                            btn: ['确认', '取消'],
                            content: $("#insert_member_proportion") //注意，如果str是object，那么需要字符拼接。
                            , yes: function (index, layero) {
                                var index1 = layer.index;
                                var reverse_multiple_min = $("#reverse_multiple_min").val();
                                var reverse_multiple_max = $("#reverse_multiple_max").val();
                                var reverse_multiple_count_min = $("#reverse_multiple_count_min").val();
                                var reverse_multiple_count_max = $("#reverse_multiple_count_max").val();
                                if ("" == reverse_multiple_min.trim()) {
                                    layer.msg("不能为空");
                                    return false;
                                } else if ("" == reverse_multiple_max.trim()) {
                                    layer.msg("不能为空");
                                    return false;
                                }else if("" == reverse_multiple_count_min.trim()){
                                    layer.msg("不能为空");
                                    return false;
                                }else if("" == reverse_multiple_count_max.trim()){
                                    layer.msg("不能为空");
                                    return false;
                                }
                                let verifyLevel = $("#verifyLevel").html();
                                if (verifyLevel) {
                                    return false;
                                }

                                $.ajax({
                                    url: "/system/activity/generalIntegral/insertReverseMultipleRule",
                                    type: "get",
                                    data: {reverse_multiple_min: reverse_multiple_min
                                        ,reverse_multiple_max:reverse_multiple_max
                                        , reverse_multiple_count_min: reverse_multiple_count_min
                                        ,reverse_multiple_count_max:reverse_multiple_count_max
                                    },
                                    success: function (data) {
                                        layer.msg(data.msg, {
                                                time: 600
                                            }
                                            , function () {
                                                //执行重载
                                                table.reload('userTableReload', {
                                                    page: {
                                                        curr: 1 //重新从第 1 页开始
                                                    }
                                                });
                                                layer.close(index1);
                                            });
                                    },
                                    //未执行
                                    fail: function (data) {
                                    }
                                })
                            }
                        });
                        break;
                    case "getDelete":
                        getCheckData();
                    function getCheckData() {
                        console.log(data);//获取选中数据
                        var delList = new Array();
                        for (var i = 0; i < data.length; i++) {
                            delList.push(data[i].id);
                        }
                        if (delList.length == 0) {
                            layer.msg("请勾选后再删除!");
                            return false;
                        }
                        var strify = delList;
                        console.log(strify);
                        $.ajax({
                            url: "/system/activity/generalIntegral/deleteReverseMultipleRule",
                            type: 'get',
                            dataType: 'json',
                            data: {
                                id: strify
                            },
                            success: function (data) {
                                if (data == 0) {
                                    layer.msg('删除失败！', {icon: 5, offset: "auto", time: 2000});//提示框
                                } else {
                                    layer.msg('删除成功！', {icon: 6, offset: "auto", time: 2000});//提示框
                                }
                                setTimeout(function () {
                                    location.reload();//重新加载页面表格
                                }, 2100);
                            }
                        })
                    }
                        break;
                    default:
                        break;
                };
            });
            //监听工具条
            table.on('tool(plan-filter)', function (obj) { //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                var layer = layui.layer, $ = layui.$;
                if (layEvent === 'detail') { //查看
                    //window.open('/system/activity/generalIntegral?id=' + data.id);
                    var id = data.id;
                    let le = data.integral_increment;
                    let proporton=data.proportion;
                    let level=data.level;
                    $("#id").val(id)
                    $("#proporton").val(proporton);
                    $("#level1").val(level);
                    layer.open({
                        type:1,
                        title: "积分",
                        area: ['400px', '190px'],
                        btn: ["确定", "取消"],
                        content: $("#GeneralIntegralSpeedCheck"),
                        /*yes: function (index, layero) { // 确认按钮回调函数
                            // 监听提交按钮
                            var valus = $("#integralIncrement").val();
                            $.ajax({
                                type: "get",
                                url: "/system/activity/generalIntegral/updateProductIntegralRule",
                                data: {integral_increment: valus,"id":id},
                                dataType: "json",
                                success: function () {
                                    //$("#motaikuang1").css("display","none")
                                    alert("修改成功");
                                }
                            })
                        },*/
                        btn2: function (index, layero) { // 取消按钮回调函数
                            //$("#motaikuang1").css("display","none")
                            layer.close(index); // 关闭弹出层
                        }
                    });
                } else if (layEvent === 'del') { //删除
                    layer.confirm('是否确认删除？', function (index) {
                        obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        layer.close(index);
                        //向服务端发送删除指令
                        $.post("/system/activity/generalIntegral/deleteReverseMultipleRule", {
                                id: data.id
                            },
                            function (data) {
                                if (data.code == 0) {
                                    alert("删除成功");
                                } else {
                                    alert("删除失败");
                                }
                            });
                    });
                } else if (layEvent === 'edit') {
                    // var checkStatus = table.checkStatus('id');
                    var id = data.id;
                    let reverse_multiple_min1 = data.reverse_multiple_min;
                    let reverse_multiple_max1 = data.reverse_multiple_max;
                    let reverse_multiple_count_min1 = data.reverse_multiple_count_min;
                    let reverse_multiple_count_max1 = data.reverse_multiple_count_max;
                    $("#reverse_multiple_min1").val(reverse_multiple_min1);
                    $("#reverse_multiple_max1").val(reverse_multiple_max1);
                    $("#reverse_multiple_count_min1").val(reverse_multiple_count_min1);
                    $("#reverse_multiple_count_max1").val(reverse_multiple_count_max1);
                    layer.open({
                        type:1,
                        title: "积分规则修改",
                        area: ['900px', '300px'],
                        btn: ["确定", "取消"],
                        content: $("#motaikuang"),
                        yes: function (index, layero) { // 确认按钮回调函数
                            // 监听提交按钮
                            var reverse_multiple_min = $("#reverse_multiple_min1").val();
                            var reverse_multiple_max = $("#reverse_multiple_max1").val();
                            var reverse_multiple_count_min = $("#reverse_multiple_count_min1").val();
                            var reverse_multiple_count_max = $("#reverse_multiple_count_max1").val();
                            $.ajax({
                                type: "get",
                                url: "/system/activity/generalIntegral/updateReverseMultipleRule",
                                data: {
                                    reverse_multiple_min: reverse_multiple_min
                                    ,"id":id
                                    ,reverse_multiple_max:reverse_multiple_max
                                    ,reverse_multiple_count_min:reverse_multiple_count_min
                                    ,reverse_multiple_count_max:reverse_multiple_count_max
                                },
                                dataType: "json",
                                success: function () {
                                    $("#motaikuang").css("display","none")
                                    alert("修改成功");
                                }
                            })
                        },
                        btn2: function (index, layero) { // 取消按钮回调函数
                            $("#motaikuang").css("display","none")
                            layer.close(index); // 关闭弹出层
                        }
                    });
                }
            });
        });
    });
</script>
<script type="text/html" id="delete">
    <a class="layui-btn layui-btn-xs" lay-event="detail">查看方案</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</html>
